var placeholder02html =[];//存放多选时的html
var placeholder02htmlinit =[];
var spanhtml = '';
var crmCustomerIdOne='';
var order_status =[];//订单状态

//渠道
ascription2()
function ascription2() {
    $.ajax({
        type: "post",
        url:root.dockingplatform.allChannelConfig,
        // url: 'https://'+ window.location.host +'/api/admin/apreorder/channelConfig/allChannelConfig',
        cache: false,  //禁用缓存
        dataType: "json",
        data: {

        },
        success: function (data) {
            console.log(data)
            if(data.errorCode=="0") {
                var dataInter=data.data;
                var interText = doT.template($("#ascription_bob").text());
                $("#ascription_lsit").html(interText(dataInter));
            }

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}


/*从代客下单跳转的*/
if(sessionStorage.getItem("Identification")){
    $("#orderCode").val(sessionStorage.getItem("orderId"));
    getList();
    // alert(sessionStorage.getItem("orderId"))
    orderInfo('订单详情','prepare-info.html',sessionStorage.getItem("orderId"))
}
/*获取收货地址*/
discountdata(123)
function discountdata (val) {
    if(val==123){
        //初始化 省
        var user_data = {
            level: '101',
            // memberId:'10258',
        }
        var succCallBack = function (data, status, response) {
            console.log(data)
            if(data.errorCode=="0"){
                var tab_data=data.list;
                if(tab_data==''){
                    cer+='<option value=""></option>'
                    $("#getArea").html(cer);
                }else{
                    var cer="<option value=''>请选择收货区域</option>"
                    for(var i=0; i<tab_data.length; i++){
                        cer+='<option value="'+tab_data[i].code+'">'+tab_data[i].name+'</option>'
                    }
                    $("#getArea").html(cer);
                }
            }
        };
        web.doAjax(root.member.getLowerAddress,'post',user_data, succCallBack);
    }else if(val==1){
        //市
        var special=$('#getArea').val()
        if(special==""){
            var cer="<option value=''>请选择收货位置</option>"
            $("#getPlace").html(cer);
        }else {
            var user_data = {
                level: '102',
                // memberId:'10258',
                parentCode:special
            }
            var succCallBack = function (data, status, response) {
                if(data.errorCode=="0"){
                    var tab_data=data.list;
                    if(tab_data==''){
                        cer+='<option value=""></option>'
                        $("#getPlace").html(cer);
                    }else{
                        var cer="<option value=''>请选择收货位置</option>"
                        for(var i=0; i<tab_data.length; i++){
                            cer+='<option value="'+tab_data[i].code+'">'+tab_data[i].name+'</option>'
                        }
                        $("#getPlace").html(cer);
                    }
                }
            };
            web.doAjax(root.member.getLowerAddress,'post',user_data, succCallBack);
        }
    }
}
/*表格渲染*/
var dataSource = new Array();
//table的数据源
var table;   //table对象
dataSource = [];

function orderList(data) {
    console.log(data)
    dataSource.splice(0, dataSource.length);//清空数组
if(data.data!=null){

    $.each(data.data.result, function (i, field) {
        var rowData = new Array();
        rowData.push(field.channelOrderId);
        rowData.push(field.orderId);
        rowData.push(field.createdOrderAt);
        rowData.push(field.pushOrderAt);
        rowData.push(field.exceptionType);
        rowData.push(field.listAddressReceiver[0]);
        rowData.push(field.sentType);
        rowData.push(field.finalTotalAmount);
        rowData.push(field.orderRemark);
        rowData.push(field.salesManagerName);
        rowData.push(field.orderStatus);
        rowData.push(field.orderChildIds);
        rowData.push(field.uploadProofStatus); //12
        rowData.push(field.parentOrderId); //13
        dataSource.push(rowData);
    });
}

    initDataTable(dataSource);

    function initDataTable(dataSource) {
        var dttable = $('#datatable').dataTable(); // 初始化dataTable，清空上一个值
        dttable.fnClearTable(); //清空一下table
        dttable.fnDestroy(); //还原初始化了的datatable
        $("#datatable").DataTable({
            "order": [[ 1, "desc" ]],
            "autoWidth": false,
            "ordering": false,
            "searching": true,
            "paging": false,
            "retrieve": true,
            "destroy": true,
            "bAutoWidth": true,
            "bLengthChange": true,
            "aLengthMenu": [5, 10, 25, 50],
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                },
                "sZeroRecords": "没有检索到数据",
                "sProcessing": "<img src='./loading.gif' />",
            },
            data: dataSource,
            columnDefs: [
                {
                    "visible": true,
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[0]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[1]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 1
                },

                {
                    "render": function (data, type, row, meta) {
                        var val = '';
                        var date = row[2];
                        var split = date.split(" ");
                        val = split[0] + '<br/>' + split[1];
                        return val;
                    },
                    "targets":2
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = '';
                        var date = row[3];
                        var split = date.split(" ");
                        val = split[0] + '<br/>' + split[1];
                        return val;
                    },
                    "targets":3
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = "";
                        if (row[4]==null || row[4]=='' || row[4]==undefined){
                            return val;
                        }
                        var abnormalType = "";
                        var abnormalTypeArr = [];
                        var rowArr = row[4].split(',');
                        for(var i = 0; i < rowArr.length; i++) {
                            abnormalTypeArr.push(getAbnormalType(rowArr[i]));
                        }
                        for(var j = 0; j < abnormalTypeArr.length; j++) {
                            if(j < abnormalTypeArr.length - 1) {
                                abnormalType += abnormalTypeArr[j] + ";";
                            } else {
                                abnormalType += abnormalTypeArr[j] + "";
                            }
                        }
                            /*if(row[4]==10){
                                val = "无异常";
                            }else if(row[4]==10){
                                val = "缺失配送信息";
                            }else if(row[4]==10){
                                val = "大额订单";
                            }else if(row[4]==10){
                                val = "超可用额度";
                            }else if(row[4]==10){
                                val = "超卖订单";
                            }else if(row[4]==10){
                                val = "低于成本价";
                            }else if(row[4]==10){
                                val = "超内部赊欠额度";
                            }else if(row[4]==10){
                                val = "结算价异常";
                            }*/
                        return abnormalType;
                    },
                    "targets":4
                },
                {
                    "render": function (data, type, row) {
                        var hhh
                        if (row[5]==undefined || row[5]==null){
                            hhh=""
                        }else{
                            hhh=row[5].receiverName
                        }
                        var val = '<div>' + hhh + '</div>';
                        return val;
                    },
                    "targets": 5
                },
                {
                    "render": function (data, type, row, meta) {
                        var senttype = "";
                        switch (row[6]) {
                            case 10:
                                senttype = "快递";
                                break;
                            case 20:
                                senttype = "快运";
                                break;
                            case 30:
                                senttype = "专车包车";
                                break;
                            case 40:
                                senttype = "鑫方盛物流";
                                break;
                            case 53:
                                senttype = "无人仓自提";
                                break;

                        }
                        var val = '<span>' + senttype + '</span>';
                        return val;
                    },
                    "targets": 6
                },

                {
                    "render": function (data, type, row) {
                        var val = '<span>'+(row[7]).toFixed(2)+'</span>';
                        return val;
                    },
                    "targets": 7
                },

                {
                    "render": function (data, type, row) {
                        var val = '<span id="consignee" onmousemove="over(\''+row[1]+'\')" onmouseout="out(\''+row[1]+'\')" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;width:50px;display:inline-block;">'+row[8]+'</span> <div id="mouseBox'+row[1]+'" style="position:absolute;max-width: 163px; background: #fff;padding:10px;border:1px solid #ccc;display:none;">'+row[8]+'</div>';
                        return val;
                    },
                    "targets": 8
                },
                {
                    "render": function (data, type, row) {
                        var val = '<span>'+(row[9])+'</span>';
                        return val;
                    },
                    "targets": 9
                },
                {
                    "render": function (data, type, row, meta) {
                        var state = "";
                        switch (row[10]) {
                            case 9:
                                $("#affirmMoney").css({
                                    display: "inline"
                                });
                                return "待付款";
                                break;
                            case 10:
                                $("#affirmMoney").css({
                                    display: "inline"
                                });
                                return "待付款";
                                break;
                            case 20:
                                $("#detailCancel").css({
                                    display: "inline"
                                });
                                $("#pass").css({
                                    display: "inline"
                                });
                                return "待审核";
                                break;
                            case 30:
                                $("#detailCancel").css({
                                    display: "inline"
                                });
                                /*$("#clientRejection").css({
                                    display: "inline"
                                });*/
                                return "待配货";
                                break;
                            case 40:
                                $("#detailCancel").css({
                                    display: "inline"
                                });
                                return "待出库";
                                break;
                            case 50:
                                $("#detailCancel").css({
                                    display: "inline"
                                });
                                return "待发货";
                                break;
                            case 60:
                                $("#clientRejection").css({
                                    display: "inline"
                                });
                                return "待收货";
                                break;
                            case 70:
                                $("#returnGoods").css({
                                    display: "inline"
                                });
                                $("#maintain").css({
                                    display: "inline"
                                });
                                $("#affirmMoney").css({
                                    display: "inline"
                                });
                                return "已收货，待结算";
                                break;
                            case 80:
                                $("#returnGoods").css({
                                    display: "inline"
                                });
                                $("#maintain").css({
                                    display: "inline"
                                });
                                return "订单成功";
                                break;
                            case 90:
                                $("#returnGoods").css({
                                    display: "inline"
                                });
                                $("#maintain").css({
                                    display: "inline"
                                });
                                return "交易完成";
                                break;
                            case 100:
                                $("#buyAgain").css({
                                    display: "inline"
                                });
                                $("#cancleReason").css({
                                    display: "inline"
                                });
                                return "已取消";
                                break;
                            case 110:
                                $("#returnReason").css({
                                    display: "inline"
                                });
                                return "交易关闭";
                                break;
                            case 120:
                                $("#returnReason").css({
                                    display: "inline"
                                });
                                return "临采商品订单";
                                break;
                            case 130:
                                $("#returnReason").css({
                                    display: "inline"
                                });
                                return "危险品订单";
                                break;
                        }
                        var val = '<span>' + state + '</span>';
                        return val;
                    },
                    "targets": 10
                },


                {
                    "render": function (data, type, row) {
                        if (row[12]==1) {
                            var val = '已上传';
                            return val;
                        }else{
                            var val = "未上传"
                            return val;
                        }

                    },
                    "targets": 11
                },

                {
                    "render": function (data, type, row) {
                        if (row[11]!="" && row[11]!=null) {
                            var val = '<span class="list powerButton 613"><a onclick="orderInfo(\'订单详情\',\'prepare-info.html\',\''+row[1]+'\',\''+row[11]+'\',\''+row[11]+'\',\''+row[13]+'\')">订单详情</a></span><br><span><a onclick="viewSuborder(\'' + row[1] + '\')">查看子订单</a></span>';
                            return val;
                        }else {
                            var val = '<span class="list powerButton 613"><a onclick="orderInfo(\'订单详情\',\'prepare-info.html\',\''+row[1]+'\',\''+row[11]+'\',\''+row[11]+'\',\''+row[13]+'\')">订单详情</a></span>';
                            return val;
                        }
                    },
                    "targets": 12
                }
            ]
        });
        //权限控制函数
        power()
    };
}

//查看子订单
function viewSuborder(val) {
    $("#viewSuborder").modal("show");
    $.ajax({
        type: "POST",
        url: root.dockingplatform.selectSubOrderIdList,
        cache: false, //禁用缓存
        dataType: "json",
        data: {
            "orderId": val, // 订单编号
        },
        success: function(result) {
            var viewSubordertale="";
            var datas=result.data;
            for(var k=0;k<datas.length;k++) {
                if(datas[k]!=null){
                    viewSubordertale += ' <div class="clearfix">' +
                        ' <label>子订单：</label><a class="formControls w-150 ml-10 lh-26" onclick="orderInfo(\'订单详情\',\'prepare-info.html\',\'' + datas[k] + '\')">' + datas[k] + '</a>' +
                        '</div>';
                }

            }
            $("#viewSuborders").html(viewSubordertale)
        },

    });
}
//关闭
function closeodel() {
    $("#viewSuborder").modal("hide");
}


/*订单备注鼠标移出事件*/
function over(id) {
    $("#mouseBox"+id).css({
        display: "inline"
    });
}
function out(id) {
    $("#mouseBox"+id).css({
        display: "none"
    });
}

function getList(){
    var a
    if($("#paid_amount_min").val()!=null && $("#paid_amount_max").val()!=null){
        if (parseFloat($("#paid_amount_max").val())<=parseFloat($("#paid_amount_min").val())){
            var s = "输入金额应大于第1个输入框";
            $.Huimodalalert(s,1000);
            return false;
        }
    }
    if($("#ascription_lsit").val() == null){
        a = '';
    }else{
        a = $("#ascription_lsit").val()
    }

    var allException= sessionStorage.getItem("examstatus")
    if(allException != 1){
        allException = 0
    }else{
        allException = 1
    }

    /*if ($('#ascription_lsit option:selected') .val()==""){

        layer.msg("请选择渠道商");
        return;
    }*/
    var per={};
            per = {
                pageNum: 1, //当前页码
                pageSize: 50,//每页显示条数
                "customerCode":$('#customerName').attr("data-customerCode"),//客户编码
                "parentCustomerCode":a,//渠道商id
                "channelOrderId":$("#dorderCode").val(),
                "salesManagerName":$("#sales_manager_name").val(), // 业务员
                "orderId":$("#orderCode").val(),
                "warehouseId": $("#shippingWarehouse option:selected").val(),//发货仓
                "skuCode":$("#SKUCode").val(),
                "orderStatus":order_status.toString(),
                "exceptionType":$("#exceptionType").val(),
                "createdOrderAtStart":$("#timemin").val(),
                "createdOrderAtEnd":$("#timemax").val(),
                "pushOrderAtStart":$("#tuisongmin").val(),
                "pushOrderAtEnd":$("#tuisongmax").val(),
                "receiverName":$("#consignee").val(),
                "receiverTelephone":$("#phoneNum").val(),
                "receiverProvince":$("#getArea").val(),
                "receiverCity":$("#getPlace").val(),
                "sentType":$("#sent_type").val(),
                "amountMin":$("#paid_amount_min").val(),
                "amountMax":$("#paid_amount_max").val(),
                "secondarySentType":$("#secondary_sent_type").val(),
                "orderSplitStatus":$("#orderSplitStatus").val(),
                "uploadProofStatus":$("#uploadProofStatus").val(),
                "allException":allException,
                "channelSigningStatus":$("#channelSigningStatus").val(),
                "orderFulfillment":$("#orderFulfillment").val(),
                "channelOrderStatus":$("#channelOrderStatus").val()
            };

    $.ajax({
        contentType: "application/json",
        type: "POST",
        url: root.dockingplatform.queryPreOrderList,
        cache: false,  //禁用缓存
        dataType: "json",
        data: JSON.stringify(per),
        success: function (result) {
            sessionStorage.setItem("examstatus",'')
            sessionStorage.setItem("parent_customer_code",$("#ascription_lsit").val());
            isIng = false;
            orderList(result);
            $('.M-box3').pagination({
                pageCount: result.data.totalPage,
                jump: true,
                coping: true,
                prevContent: '上页',
                nextContent: '下页',
                callback: function (api) {
                    var perdd={};
                            perdd = {
                                pageNum: api.getCurrent(), //当前页码
                                pageSize: 50,//每页显示条数
                                "customerCode":$('#customerName').attr("data-customerCode"),//客户编码
                                "parentCustomerCode":a,//渠道商id
                                "channelOrderId":$("#dorderCode").val(),
                                "salesManagerName":$("#sales_manager_name").val(), // 业务员
                                "orderId":$("#orderCode").val(),
                                "skuCode":$("#SKUCode").val(),
                                "orderStatus":order_status.toString(),
                                "warehouseId": $("#shippingWarehouse option:selected").val(),//发货仓
                                "exceptionType":$("#exceptionType").val(),
                                "createdOrderAtStart":$("#timemin").val(),
                                "createdOrderAtEnd":$("#timemax").val(),
                                "pushOrderAtStart":$("#tuisongmin").val(),
                                "pushOrderAtEnd":$("#tuisongmax").val(),
                                "receiverName":$("#consignee").val(),
                                "receiverTelephone":$("#phoneNum").val(),
                                "receiverProvince":$("#getArea").val(),
                                "receiverCity":$("#getPlace").val(),
                                "sentType":$("#sent_type").val(),
                                "amountMin":$("#paid_amount_min").val(),
                                "amountMax":$("#paid_amount_max").val(),
                                "secondarySentType":$("#secondary_sent_type").val(),
                                "orderSplitStatus":$("#orderSplitStatus").val(),
                                "uploadProofStatus":$("#uploadProofStatus").val(),
                                "allException":allException,
                                "channelSigningStatus":$("#channelSigningStatus").val(),
                                "orderFulfillment":$("#orderFulfillment").val()
                            };
                    $.ajax({
                        contentType: "application/json",
                        type: "POST",
                        url:root.dockingplatform.queryPreOrderList,
                        cache: false,  //禁用缓存
                        dataType: "json",
                        data: JSON.stringify(perdd),
                        success: function (result) {
                            orderList(result);
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                        }
                    });
                }
            });
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
        }
    });
}


//弹框跳转
var allException= sessionStorage.getItem("examstatus")

console.log(allException)
if(allException==1){
    getList()
}else{
    getList()
}



/*跳转订单详情*/
function orderInfo(title,url,data,uploadStatus,uploadStatus1,parentOrderId){
    sessionStorage.setItem("orderId",data);
    sessionStorage.setItem("uploadStatus",uploadStatus);
    sessionStorage.setItem("parentOrderId",parentOrderId);
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}



//自提点
//myFunctions();
function myFunctions(){
    $("#selfMentionPointNames").val("");
    var user_data = {
        pWarehouseCode:$("#shippingWarehouse option:selected").val()

    }
    var succCallBack = function (data, status, response) {
        console.log(data)
        if(data.errorCode=="0"){
            var jsonObj =data.data;
            if(jsonObj=="" ||$("#shippingWarehouse option:selected").val()==""){
                $("#tuan").html("<li>无数据</li> ");
            }else {
                console.log(jsonObj);

                var optionstring = "";
                for (var  i= 0; i < jsonObj.length; i++) {
                    optionstring += "<li onclick='relation("+ jsonObj[i].warehouseCode+",\""+jsonObj[i].selfMentionPointName+"\")' data-align=\"" + jsonObj[i].warehouseCode + "\" > " + jsonObj[i].selfMentionPointName + "</li>";
                }
                $("#tuan").html(optionstring);
                console.log(jsonObj)
            }
        }else{
            $("#tuan").html("<li>无数据</li> ");
        }
    }
    web.doAjax(root.orderInter.queryStoreAddressByPwarehouseCode,'post',user_data, succCallBack);

}
//取光标
$("#selfMentionPointNames").focus(function () {
    $("#tuan").show()
});
$(document).bind("click",function(e){
    //id为menu的是菜单，id为open的是打开菜单的按钮
    if($(e.target).closest("#tuan").length == 0 && $(e.target).closest("#selfMentionPointNames").length == 0){
        //点击id为menu之外且id不是不是open，则触发
        $("#tuan").hide()
    }
})
function relation(id,ce) {
    $("#selfMentionPointNames").val(ce).text(id)
    $("#tuan").hide()
    console.log($("#selfMentionPointNames").text())
}
function getAbnormalType(typeCode) {
    switch(typeCode) {
        case "10":
            return "无异常";
            break;
        case "20":
            return "大额订单";
            break;
        case "30":
            return "超可用额度";
            break;
        case "40":
            return "超卖订单";
            break;
        case  "50":
            return "低于成本价";
            break;
        case  "60":
            return "结算价异常";
            break;
        case  "70":
            return "非我司商品";
            break;
        case  "80":
            return "商品已下架";
            break;
        case  "90":
            return "商品无结算价";
            break;
        case  "100":
            return "运费金额异常";
            break;
        case  "110":
            return "超可执行赊欠额度";
            break;
        case  "120":
            return "临采商品订单";
            break;
        case  "130":
            return "危险品订单";
            break;
        case  "140":
            return "经纬度异常";
            break;
        case  "150":
            return "议价单异常";
            break;
        case  "160":
            return "服务商商品";
            break;
    }
}

// 客户名称
$('#customerName').on('input',function(){
    var parentCustomerCode = $("#ascription_lsit").val();
    if(!parentCustomerCode){
        layer.msg('请选择所属渠道',{offset:'t'});
        return ;
    }
    var value = $('#customerName').val();
    customerInfo(value);
    $('.customerLists').show();
});
// 客户名称某一项
$('.customerLists').delegate('li','click',function(){
    var itemLi = $(this).text();
    $('#customerName').val(itemLi);
    var customerCode =  $(this).attr('data-id');
    $('#customerName').attr("data-customerCode",customerCode);
    $('.customerLists').hide();
});
$(document).on('click',function(){
    $('.channelLists').hide();
    $('.customerLists').hide();
});
// 客户名称
function customerInfo(value){
    var parentCustomerCode = $("#ascription_lsit").val();
    var params = {
        customerName:value,
        parentCustomerCode:parentCustomerCode
        /*parentCustomerCode:'D000000022'*/
    }
    var successData = function(data){
        if(data.errorCode == 0){
            var result = data.data;
            if(result && result.length >0){
                var channelItem =  '';
                result.forEach(function(item,index){
                    channelItem +="<li class='clearfix pl-10 mb-5' data-id='"+item.customerCode+"'>"+item.customerName+"</li>"
                });
                $('.customerLists').html(channelItem)
            }else{
                var empty = '<li class="clearfix pl-10 mb-5">无数据</li>';
                $('.customerLists').html(empty)
            }
        }
    }
    return web.doAjax(root.dockingplatform.seachSubChanelConfigByName, 'post', params, successData, 1);
}

//交易状态

$(".ulbox").css('display','none');
/*点击 项目 显示下拉 选项,其中全选全不选，要做传值的处理*/
$(".dataval,.icon_arrow").on('click',function (e) {
    $(this).parent().children(".icon_arrow").toggleClass("icon_arrow_down");
    if($('.ulbox').css("display") == "none"){
        $('.ulbox').show();
        if($(".placeholder02").find(".all-radius")&&$(".placeholder02").find(".all-radius").html()=="全部"){
            $(".placeholder02").html("")

        }
    }else{
        $(".ulbox").hide();
        if ($(".placeholder02").html()==""){
            $(".placeholder02").html('<span class="all-radius">全部</span>')
        }
    }
    /*------------------8.24 如果已经有选择过的--------------------*/
    var initcustomerId =[];
    placeholder02htmlinit=[]
    $.each($(".lidata"),function (index,itm) {

        initcustomerId.push($(itm).attr('crmCustomerId'))
        placeholder02htmlinit.push($(itm).attr('crmCustomername'))
    })
    if(order_status.length >0){
        function isArray(str){
            return Object.prototype.toString.call(str) == "[object Array]";
        }
        if(isArray(order_status)){
            order_status= [order_status].join().split(',');
        }else{
            order_status= [order_status].join().split(',');
        }
        console.log(order_status)
        $.each($(".lidata"),function (index,itm) {
            $.each(order_status,function (i,item) {
                $.each(initcustomerId,function (j,ite) {
                    if(item == ite){
                        if($("itm").attr('crmcustomerid')==item){
                            $(".lidata").find('.evetyipt').prop('checked',true);
                        }
                    }
                })
            })
        })

    }
    e.stopPropagation();
});
var checkednum=0;
//当点击下拉数据时 回显在input里面
var htmlspan='';
$(".ulbox").on('click','input.evetyipt',function (e) {
    if($(".placeholder02").find(".all-radius")&&$(".placeholder02").find(".all-radius").html()=="全部"){
        $(".placeholder02").html("")

    }
    e.stopPropagation();
    if($(this).prop('checked')){
        $(this).prop('checked',true);//选中
        checkednum ++;
        spanhtml=$(this).next().html();
        placeholder02html.push(spanhtml);
        crmCustomerIdOne = $(this).parent().attr('crmCustomerId');
        order_status.push(crmCustomerIdOne);
        $.each(placeholder02html,function(i,item){
            htmlspan = '<span>'+item+'</span>'
        })
        $(".placeholder02").append(htmlspan);
        if($(".ulbox").find('input.evetyipt').length == checkednum){
            $(".checkboxall").prev().prop('checked',true);
        }
        //全选反选时会用
        if (checkednum==0) {
            $(".checkboxall").prev().prop('checked',true);

        }
        //判断如果只选择了一个下拉选项 在input 里面应该展示全部的名称
        onenameadd()
    }else{
        checkednum --;
        $(this).prop('checked',false);
        var checkfalsehtml =  $(this).next().html();
        var tt =$(this).parent().attr('crmCustomerId');
        for (var i=0;i<order_status.length;i++){
            if(order_status[i] == tt){
                order_status.splice(order_status.indexOf(tt),1);
            }
        }
        var iptspandata = $('.placeholder02 span');//点击选中回显在span 里面的值
        $.each(iptspandata,function (i,item) {
            if($(item).html() == checkfalsehtml){
                $(item).html('');
                $(item).remove();
            }
        });
        placeholder02html.splice($(this).next().html(),1);
        if($(".ulbox").find('input.evetyipt').length != checkednum){
            $(".checkboxall").prev().prop('checked',false);
        }
        onename();
    }
});
//可点击空白处
$(document).click(function() {
    $(".ulbox").css('display','none');
    if ($(".placeholder02").html()==""){
        $(".placeholder02").html('<span class="all-radius">全部</span>')
    }
});
function onenameadd(){
    //判断如果只选择了一个下拉选项 在input 里面应该展示全部的名称
    if(order_status.length == 1){
        $(".placeholder02 span").css('max-width','none');
        $(".placeholder02 span").attr('title',$(".placeholder02 span").html());
    }else{
        $(".placeholder02 span").css('max-width','48px');
    }
}
function onename(){
    //判断如果只选择了一个下拉选项 在input 里面应该展示全部的名称
    if(order_status.length == 1){
        $(".placeholder02 span").css('max-width','none');
        $(".placeholder02 span").attr('title',$(".placeholder02 span").html());
    }
}

/*点击全选 联动 传值*/
var ulboxli = $(".ulbox").find('li');
$(".checkboxall").parent().on('click','input',function (e) {
    e.stopPropagation();
    if($(this).prop('checked')){//全选
        $(this).prop('checked',true);
        ulboxli.find('input').prop('checked',true);
        $(".placeholder02").html("")
        placeholder02html =placeholder02htmlinit;
        var htmlspan='';
        $.each(placeholder02html,function(i,item){
            htmlspan += '<span>'+item+'</span>'
        });
        var crmCustomerIds=$(this).attr('crmCustomerId')
        order_status=crmCustomerIds.split(",")
        $(".placeholder02").append(htmlspan);
    }else{//全不选
        $(this).prop('checked',false);
        ulboxli.find('input').prop('checked',false);
        order_status=[];
        placeholder02html=[];
        $(".placeholder02").html('');
    }
});
$(".ulbox").on('click','.checkboxall',function (e) {
    e.stopPropagation();
    if(  $(this).parent().find('input').prop('checked') == false){//全选
        $(this).parent().find('input').prop('checked',true);
        ulboxli.find('input').prop('checked',true);
        placeholder02html =placeholder02htmlinit;
        var htmlspan='';
        $.each(placeholder02html,function(i,item){
            htmlspan += '<span>'+item+'</span>'
        });
        $(".placeholder02").append(htmlspan);
    }else{//全不选
        $(this).parent().find('input').prop('checked',false);
        ulboxli.find('input').prop('checked',false);
        order_status=[];
        placeholder02html=[];
        $(".placeholder02").html('');
    }
})

function simpleExport() {
    if ($('#ascription_lsit option:selected').val() == "") {
        layer.msg("请选择渠道商");
        return false;
    }
    var customerCode11 = $("#ascription_lsit").val();//渠道商id
    var channelOrderId = $("#dorderCode").val();

    var orderId11 = $("#orderCode").val();
    var skuCode = $("#SKUCode").val();
    var orderStatus = order_status.toString();
    var exceptionType = $("#exceptionType").val();
    var createdOrderAtStart = $("#timemin").val();
    var createdOrderAtEnd = $("#timemax").val();
    var pushOrderAtStart = $("#tuisongmin").val();
    var pushOrderAtEnd = $("#tuisongmax").val();
    var receiverName11 = $("#consignee").val();
    var receiverTelephone = $("#phoneNum").val();
    var receiverProvince = $("#getArea").val();
    var receiverCity = $("#getPlace").val();
    var sentType = $("#sent_type").val();
    var amountMin = $("#paid_amount_min").val();
    var amountMax = $("#paid_amount_max").val();
    var secondarySentType = $("#secondary_sent_type").val();
    var orderSplitStatus = $("#orderSplitStatus").val();
    var uploadProofStatus = $("#uploadProofStatus").val();
    var warehouseId = $("#shippingWarehouse option:selected").val();
    var allException = sessionStorage.getItem("examstatus")
    if (allException != 1) {
        allException = 0
    } else {
        allException = 1
    }
    var pageNum = 1;
    var pageSize = 50;

    // };
    $('#putout').attr('href', root.dockingplatform.exportOrderExcel
        + '?customerCode=' + $('#customerName').attr("data-customerCode") + '&channelOrderId=' + '' + channelOrderId + '&orderId=' + '' + orderId11 + '&skuCode=' + '' + skuCode
        + '&orderStatus=' + '' + orderStatus + '&exceptionType=' + '' + exceptionType + '&createdOrderAtStart=' + '' + createdOrderAtStart + '&createdOrderAtEnd=' + '' + createdOrderAtEnd
        + '&pushOrderAtStart=' + '' + pushOrderAtStart + '&pushOrderAtEnd=' + '' + pushOrderAtEnd + '&receiverName=' + '' + receiverName11 + '&receiverTelephone=' + '' + receiverTelephone
        + '&receiverProvince=' + '' + receiverProvince + '&receiverCity=' + '' + receiverCity + '&sentType=' + '' + sentType + '&pageNum=' + '' + pageNum + '&pageSize=' + '' + pageSize
        + '&amountMin=' + '' + amountMin + '&amountMax=' + '' + amountMax + '&orderSplitStatus=' + '' + orderSplitStatus
        + '&secondarySentType=' + '' + secondarySentType + '&uploadProofStatus=' + '' + uploadProofStatus + '&allException=' + '' + allException + '&warehouseId=' + '' + warehouseId + "&parentCustomerCode=" +customerCode11)
}

function complexExport() {
    if ($('#ascription_lsit option:selected').val() == "") {

        layer.msg("请选择渠道商");
        return false;
    }
    var customerCode11 = $("#ascription_lsit").val();//渠道商id
    var channelOrderId = $("#dorderCode").val();
    var orderId11 = $("#orderCode").val();
    var skuCode = $("#SKUCode").val();
    var orderStatus = order_status.toString();
    var exceptionType = $("#exceptionType").val();
    var createdOrderAtStart = $("#timemin").val();
    var createdOrderAtEnd = $("#timemax").val();
    var pushOrderAtStart = $("#tuisongmin").val();
    var pushOrderAtEnd = $("#tuisongmax").val();
    var receiverName11 = $("#consignee").val();
    var receiverTelephone = $("#phoneNum").val();
    var receiverProvince = $("#getArea").val();
    var receiverCity = $("#getPlace").val();
    var sentType = $("#sent_type").val();
    var amountMin = $("#paid_amount_min").val();
    var amountMax = $("#paid_amount_max").val();
    var secondarySentType = $("#secondary_sent_type").val();
    var orderSplitStatus = $("#orderSplitStatus").val();
    var warehouseId = $("#shippingWarehouse option:selected").val();
    var allException = sessionStorage.getItem("examstatus")
    if (allException != 1) {
        allException = 0
    } else {
        allException = 1
    }
    var pageNum = 1;
    var pageSize = 50;

    $('#putout1').attr('href', root.dockingplatform.exportOrderItemExcel
        + '?customerCode=' + $('#customerName').attr("data-customerCode") + '&channelOrderId=' + '' + channelOrderId + '&orderId=' + '' + orderId11 + '&skuCode=' + '' + skuCode
        + '&orderStatus=' + '' + orderStatus + '&exceptionType=' + '' + exceptionType + '&createdOrderAtStart=' + '' + createdOrderAtStart + '&createdOrderAtEnd=' + '' + createdOrderAtEnd
        + '&pushOrderAtStart=' + '' + pushOrderAtStart + '&pushOrderAtEnd=' + '' + pushOrderAtEnd + '&receiverName=' + '' + receiverName11 + '&receiverTelephone=' + '' + receiverTelephone
        + '&receiverProvince=' + '' + receiverProvince + '&receiverCity=' + '' + receiverCity + '&sentType=' + '' + sentType + '&pageNum=' + '' + pageNum + '&pageSize=' + '' + pageSize
        + '&amountMin=' + '' + amountMin + '&amountMax=' + '' + amountMax + '&orderSplitStatus=' + '' + orderSplitStatus
        + '&secondarySentType=' + '' + secondarySentType + '&allException=' + '' + allException + '&warehouseId=' + '' + warehouseId + "&parentCustomerCode=" +customerCode11)
}